<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>文章添加--layui后台管理模板</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<link rel="stylesheet" href="../../layui/css/layui.css" media="all" />

<script src="../../js/layui/layui.js"></script>
<script type="text/javascript" src="../../release/wangEditor.js"></script>
<link rel="stylesheet" href="../../css/font_eolqem241z66flxr.css"
	media="all" />
</head>
<body class="childrenBody">
	<form class="layui-form" id="news" lay-filter="newsForm">
		<input type="hidden" name="id" />
		<div class="layui-form-item">
			<label class="layui-form-label"><span style="color: red;">*
			</span>新闻标题</label>
			<div class="layui-input-block">
				<input type="text" class="layui-input newsName" name="nTitle"
					lay-verify="required" placeholder="请输入新闻标题">
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label"><span style="color: red;">*
				</span>是否精选</label>
				<div class="layui-input-block">
					是 <input type="radio" name="nChoice" value="true" class="tuijian"
						checked="checked"> 否 <input type="radio" name="nChoice"
						value="false" class="newsStatus">
				</div>
			</div>

			<div class="layui-inline">
				<label class="layui-form-label"><span style="color: red;">*
				</span>发布时间</label>
				<div class="layui-input-inline">
					<input type="text" class="layui-input newsTime" lay-verify="date"
						name="nTime" id="time">
				</div>
			</div>
			<div class="layui-inline">
				<label class="layui-form-label"><span style="color: red;">*
				</span>新闻类型</label>
				<div class="layui-input-inline">
					<select name="ntId" id="ntId" class="newsLook"
						lay-filter="browseLook">

					</select>
				</div>
			</div>
		</div>
		<div class="layui-form-item" style="margin-top: 70px">
			<label class="layui-form-label"><span style="color: red;">*
			</span>内容摘要</label>
			<div class="layui-input-block">
				<div id="nContent1"></div>
				<textarea placeholder="请输入内容摘要" class="layui-textarea"
					style="display: none;" id="nContent2" name="nContent"></textarea>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">文章内容</label>
			<div class="layui-input-block">
				<div id="news_content1"></div>
				<textarea class="layui-textarea" name="nDetails"
					style="display: none;" placeholder="请输入内容" lay-verify="content"
					id="news_content2"> </textarea>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn" lay-submit="" lay-filter="addNews">立即提交</button>
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
		</div>
	</form>

	<script type="text/javascript">
		layui.use([ 'upload', 'layer' ,'form','laydate'], function() {
			var upload = layui.upload, $ = layui.$,form=layui.form, layer = layui.layer,laydate=layui.laydate;
            var data=JSON.parse(sessionStorage.getItem("News")); 
            var E = window.wangEditor;
            var editor = new E('#news_content1');
            var editor2 = new E('#nContent1');
            editor.customConfig.onchange = function(html) {
				$("#news_content2").val(html)
			}
            editor2.customConfig.onchange = function(html) {
				$("#nContent2").val(html)
			}
			editor.create()
			editor2.create()
			$("#news_content2").val(editor.txt.html())
			 editor.txt.html(data.nDetails)
			 $("#nContent2").val(editor2.txt.html())
			 editor2.txt.html(data.nContent)
			form.val("newsForm",{
				"nTitle":data.nTitle,
				"nTime":data.nTime,
				"id":data.nId,
				"ntId":data.ntId,
				"nContent":data.nContent,
				"nDetails":data.nDetails
			});
			
			
			//form.render();
			$.post("../../../SelectServlet?reqName=selectNewsTypeAll",
					function(res) {
				 
					  if (res!=null) {
						  
						$("#ntId").empty();
						$("#ntId").append(new Option("请选择", ""));
						$.each(res,function(index, item) {
							$("#ntId").append(new Option(item.ntName,item.ntId));
							if(item.ntName==data.ntName){
								$("#ntId").children("option").eq(index+1).prop("selected", true);
							}
							});
					} else {
						
						$("#ntId").append(new Option("暂无数据", ""));
					}
					 
					  form.render();
				}, "json");
			laydate.render({
			    elem: '#time' 
			  });
		
			form.on('submit(addNews)',function(data){
				$.post(
						'../../../NewsServlet?reqName=updateNews',
								$("#news").serialize(),function(res){
							if (res) {
								var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
						        setTimeout(function(){
						            top.layer.close(index);
									top.layer.msg("新闻添加成功！");
						 			layer.closeAll("iframe");
							 		parent.location.reload();
						        },1000);
							}
						},"text"
				)
				return false;
			})
		});
	</script>

</body>
</html>